package com.huike.clue.service.Impl;


import com.huike.business.domain.TbBusiness;
import com.huike.business.mapper.TbBusinessMapper;
import com.huike.clue.domain.TbClue;
import com.huike.clue.domain.dto.TbClueDto;
import com.huike.clue.domain.dto.TbClueGainDto;
import com.huike.clue.mapper.TbClueMapper;
import com.huike.clue.service.TbClueService;
import com.huike.common.utils.bean.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TbClueServiceImpl implements TbClueService {

    @Autowired
    private TbClueMapper tbClueMapper;


    /**
     * 线索分页条件查询
     */
    @Override
    public List<TbClue> selectClue(TbClueDto dto) {
        return tbClueMapper.selectClue(dto);
    }

    /**
     * 线索池分页条件查询
     *
     * @param dto
     * @return
     */
    @Override
    public List<TbClue> selectCluePool(TbClueDto dto) {
        return tbClueMapper.selectCluePool(dto);
    }

    /**
     * 查询线索详情
     *
     * @param id
     * @return
     */
    @Override
    public TbClue selectById(Long id) {
        return tbClueMapper.selectById(id);
    }

    /**
     * 新增线索
     *
     * @param tbClue
     * @return
     */
    @Override
    public int insertClue(TbClue tbClue) {
        return tbClueMapper.insertClue(tbClue);
    }

    /**
     * 转伪线索
     *
     * @param id
     * @param
     * @return
     */
    @Override
    public int turnFalseClue(Long id, TbClue clue) {
        return tbClueMapper.turnFalseClue(id, clue.getReason(), clue.getRemark());
    }

    /**
     * 批量捞取线索
     *
     * @param ids
     * @return
     */
    @Override
    public int gainClue(TbClueGainDto ids) {
        return tbClueMapper.gainClue(ids);
    }


    @Autowired
    private TbBusinessMapper tbBusinessMapper;


    //商机与线索 交互

    /**
     * 线索转商机
     *
     * @param id
     * @return
     */
    @Override
    public int changeBusiness(Long id) {
        TbClue tbClue = tbClueMapper.selectById(id);
        tbClue.setStatus(3);  //转为商机
        tbClueMapper.update(tbClue);

       // 线索转为商机 商机字段的设置
        TbBusiness tbBusiness = new TbBusiness();
        BeanUtils.copyProperties(tbClue,tbBusiness);
        tbBusiness.setStatus("1");
        tbBusinessMapper.add(tbBusiness);
        return 1;
    }
}
